package cz.semjob.output.data;

import java.util.ArrayList;
import java.util.List;

import cz.semjob.document.annotation.LabeledWords;
import cz.semjob.document.annotation.metadata.Entity;
import cz.semjob.document.util.DocumentUtil;

public class CandidateConcept {

	private ClassificationInfo classificationInfo;

	private List<LabeledWords> words;
	
	private String representation;

	private Entity entity;

	private int occurences;

	private List<CandidateConcept> parentConcepts;

	private List<CandidateConcept> subConcepts;

	public CandidateConcept(List<LabeledWords> labeledWordsList,
			int occurences, String representation, Entity entity,
			ClassificationInfo classificationInfo) {
		super();
		this.words = labeledWordsList;
		this.occurences = occurences;
		this.parentConcepts = new ArrayList<CandidateConcept>();
		this.subConcepts = new ArrayList<CandidateConcept>();
		this.representation = representation;
		this.entity = entity;
		this.classificationInfo = classificationInfo;
	}

	public void addParentConcept(CandidateConcept parentConcept) {
		parentConcepts.add(parentConcept);
	}

	public void addParentConcepts(List<CandidateConcept> parentConcepts) {
		parentConcepts.addAll(parentConcepts);
	}

	public void addSubConcept(CandidateConcept subConcept) {
		subConcepts.add(subConcept);
	}

	public List<LabeledWords> getWords() {
		return words;
	}

	public int getOccurences() {
		return occurences;
	}

	public List<CandidateConcept> getParentConcepts() {
		return parentConcepts;
	}

	public List<CandidateConcept> getParentConcepts(Entity entity) {
		List<CandidateConcept> filteredParentConcepts = new ArrayList<CandidateConcept>();
		for (CandidateConcept parentConcept : this.parentConcepts) {
			if (parentConcept.getEntity().equals(entity)) {
				filteredParentConcepts.add(parentConcept);
			}
		}
		return filteredParentConcepts;
	}

	public String getRepresentation() {
		return representation;
	}

	public List<CandidateConcept> getSubConcepts() {
		return subConcepts;
	}

	public Entity getEntity() {
		return entity;
	}

	public String getNormalizedRepresentation() {
		return DocumentUtil.createNormalizedRepresentation(representation);
	}

	public double getRelevance() {
		return (classificationInfo.getClassifierPrecision() / classificationInfo
				.getClassifierRecall())
				* ((double) occurences / (double) classificationInfo
						.getDocumentCount());
	}

	@Override
	public String toString() {
		return "CandidateConcept [representation=" + representation
				+ ", occurences=" + occurences + ", entity=" + entity + "]";
	}

}
